﻿using System.Windows;
using System.Windows.Controls.Primitives;
using Microsoft.Practices.Prism.Commands;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.SilverlightMediaFramework.Core;
using System;

namespace Ausy.Silverlight.VideoPlayer.Common.Commands
{
    /// <summary>
    /// Cette classe représente la commande permettant de gérer la gestion de la navigation en cours
    /// </summary>
    public class MediaEndedCommand : CommandBehaviorBase<SMFPlayer>
    {
        #region Constructor

        /// <summary>
        /// Constructeur par défaut
        /// </summary>
        /// <param name="element">SMFPlayer Player</param>
        public MediaEndedCommand(SMFPlayer element)
            : base(element)
        {
            element.MediaEnded += new System.EventHandler(this.OnMediaEnded);
        }
        
        #endregion

        #region OnNavigated Method

        /// <summary>
        /// Cette méthode permet de gérer la navigation dur la Frame
        /// </summary>
        /// <param name="sender">Frame associé</param>
        /// <param name="e">Argument de navigation</param>
        private void OnMediaEnded(object sender, EventArgs e)
        {
            var player = sender as SMFPlayer;
            player.Stop();
            player.StartRewind();
            base.ExecuteCommand();
        } 

        #endregion
    }
}
